package cn.myjerry.others.commons;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.collections4.CollectionUtils;

/**
 * 集合操作
 * 1、并集
 * 	 CollectionUtils.union()
 * 2、交集
 *   CollectionUtils.intersection()
 *   CollectionUtils.retainAll();
 * 3、差集
 *   CollectionUtils.subtract()
 * @author Jerry
 *
 */
public class Demo04 {
	public static void main(String[] args) {
		Set<Integer> set1 = new HashSet<>();
		set1.add(1);
		set1.add(2);
		set1.add(3);
		set1.add(4);
		
		Set<Integer> set2 = new HashSet<>();
		set2.add(3);
		set2.add(4);
		set2.add(5);
		set2.add(6);
		
		System.out.println("=========并集============");
		Collection<Integer> unionCol = CollectionUtils.union(set1, set2);
		for(Integer temp:unionCol) {
			System.out.println(temp);
		}
		
		System.out.println("=========交集============");
		//Collection<Integer> intersectionol = CollectionUtils.intersection(set1, set2);
		Collection<Integer> intersectionol = CollectionUtils.retainAll(set1, set2);
		for(Integer temp:intersectionol) {
			System.out.println(temp);
		}
		
		System.out.println("=========差集============");
		Collection<Integer> subtractCol = CollectionUtils.subtract(set1, set2);
		for(Integer temp:subtractCol) {
			System.out.println(temp);
		}
	}
}
